package com.loongtech.bi.entity.system;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Comparator;

@Entity
@Table(name = "bi_channel")
@JsonIgnoreProperties({"comparatorId"})
public class EntityBiChannel implements Serializable {
    private static final long serialVersionUID = 3L;
    @Id
    private String id; // 主键
    // 游戏名称
    @Transient
    private String gameName;
    // 游戏id
    @Column(columnDefinition = "int(11) default 0")
    private Integer gameId;
    @Column(columnDefinition = "varchar(255) NOT NULL default ''")
    private String name;
    @Column(columnDefinition = "varchar(255) default ''")
    private String description;
    @Column(columnDefinition = "varchar(255) NOT NULL default ''")
    private String platformId;
    @Transient
    private String platformName;

    private long updateAt;        // 最后更新时间
    //auany渠道集
    @Column(columnDefinition = "varchar(255) default ''")
    private String platName;

    @PrePersist
    @PreUpdate
    public void preUpdate4UpdateAt() {
        this.setUpdateAt(System.currentTimeMillis());
    }

    @Transient
    public final Comparator<EntityBiChannel> comparatorId = new Comparator<EntityBiChannel>() {
        public int compare(EntityBiChannel s1, EntityBiChannel s2) {
            return Integer.parseInt(s1.getId()) - Integer.parseInt(s2.getId());
            //return s1.getId().compareTo(s2.getId());
        }
    };

    public String getGameName() {
        return gameName;
    }

    public void setGameName(String gameName) {
        this.gameName = gameName;
    }

    public Integer getGameId() {
        return gameId;
    }

    public void setGameId(Integer gameId) {
        this.gameId = gameId;
    }

    public String getPlatformName() {
        return platformName;
    }

    public void setPlatformName(String platformName) {
        this.platformName = platformName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getPlatName() {
        return platName;
    }

    public void setPlatName(String platName) {
        this.platName = platName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EntityBiChannel that = (EntityBiChannel) o;

        if (!id.equals(that.id)) return false;
        //if (!gameName.equals(that.gameName)) return false;
        //if (!gameId.equals(that.gameId)) return false;
        if (!name.equals(that.name)) return false;
        if (description != null ? !description.equals(that.description) : that.description != null) return false;
        if (!platformId.equals(that.platformId)) return false;
        return platName.equals(that.platName);
    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + gameName.hashCode();
        result = 31 * result + gameId.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + platformId.hashCode();
        result = 31 * result + platName.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "EntityBiChannel{" +
                "id='" + id + '\'' +
                ", gameName='" + gameName + '\'' +
                ", gameId=" + gameId +
                ", name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", platformId='" + platformId + '\'' +
                ", platName='" + platName + '\'' +
                '}';
    }

    public long getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(long updateAt) {
        this.updateAt = updateAt;
    }

    public String getPlatformId() {
        return platformId;
    }

    public void setPlatformId(String platformId) {
        this.platformId = platformId;
    }

    public static class K {
        public static final String id = "id";
        public static final String name = "name";
        public static final String platName = "platName";
        public static final String description = "description";

        // id, name, description,
        public static java.util.List<String> toList() {
            java.util.List<String> list = new java.util.ArrayList<>();
            list.add(id);
            list.add(name);
            list.add(platName);
            list.add(description);
            return list;
        }
    }
}